Skip to content

fix(table-core): sort long digit runs by value in alphanumeric sort - #6670

Open
oyobbeb wants to merge 1 commit into
TanStack:mainfrom
oyobbeb:feat-alphanumeric-long-digit-runs
Open

oyobbeb wants to merge 1 commit into
TanStack:mainfrom
oyobbeb:feat-alphanumeric-long-digit-runs

Conversation

@oyobbeb

@oyobbeb oyobbeb commented Nov 22, 2026 •

Copy link
Copy Markdown

🎯 Changes

sortFn_alphanumeric and sortFn_alphanumericCaseSensitive compare digit runs of up to 15 significant digits exactly. Longer runs fall back to parseInt, which rounds once the value no longer fits in a double, so different runs such as 1100000000000000001 and 1100000000000000002 compare as equal. A column of snowflake-style IDs sent as strings then sorts wrong when it uses alphanumeric, either directly or by registering sortFn_alphanumeric for 'auto' as the sorting example does.

This replaces only that fallback: the run with more significant digits is larger, and runs of equal length compare as digit strings, which orders them by value. The fast path for 15 digits or fewer and parseSmallInt are unchanged. This is the comparison that the perf notes for #6371 describe as "strictly more correct but observable" and left out to keep the behavior identical (perf-done.md). Digit runs that parseInt collapsed now compare by value, and so does the order those ties used to leave to the following chunks.

Added a test with four assertions to sortFns.test.ts. It fails on main.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested code changes locally with pnpm test and pnpm test:e2e, or these tests do not apply to this pull request.
  • I fully understand the code in this pull request, including any code generated with AI assistance.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Bug Fixes
    • Alphanumeric sorting now correctly orders digit sequences longer than 15 digits instead of treating some distinct values as equal. Large values are ordered by their numeric value, including when their digit counts differ. Values that differ only by leading zeros remain equivalent. This behavior applies to both standard and case-sensitive alphanumeric sorting.

@changeset-bot

changeset-bot Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c7c595e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 12 packages
Name Type
@tanstack/table-core Patch
@tanstack/alpine-table Patch
@tanstack/angular-table-devtools Patch
@tanstack/angular-table Patch
@tanstack/ember-table Patch
@tanstack/lit-table Patch
@tanstack/octane-table Patch
@tanstack/preact-table Patch
@tanstack/react-table Patch
@tanstack/solid-table Patch
@tanstack/svelte-table Patch
@tanstack/vue-table Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Alphanumeric sorting now compares digit runs longer than 15 significant digits by length and then lexicographically. The added test covers large values, differing digit lengths, and leading zeroes. A patch changeset documents the update.

Changes: Long-digit alphanumeric sorting

Layer / File(s) Summary
Compare long numeric chunks
packages/table-core/src/features/row-sorting/sortFns.ts, packages/table-core/tests/unit/fns/sortFns.test.ts, .changeset/long-digit-alphanumeric-sort.md
compareNumericChunks removes leading zeroes and compares chunks with more than 15 significant digits by length, then lexicographically. Tests cover large values, different digit lengths, and equality with leading zeroes. The changeset records the patch.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Suggested reviewers: kevinvandy

Merge Risk: Minimal · up to c7c59

This change makes alphanumeric sorting distinguish very long digit runs by value instead of treating them as equal. No actionable merge-blocking risk was found, and the change is covered by an added test.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: alphanumeric sort now compares long digit runs by value. It also follows the conventional commit format and names the affected package. The raw summary and objectives …
Description check Passed The description covers the change, its motivation, and the test added. It also fills in the template checklist and the release-impact section. It does not match the template's heading text exactly ('C…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: alphanumeric sort now compares long digit runs by value. It also follows the conventional commit format and names the affected package. The raw summary and objectives both describe this change in sortFns.ts and its test.

Full details: Description check

Explanation

The description covers the change, its motivation, and the test added. It also fills in the template checklist and the release-impact section. It does not match the template's heading text exactly ('Changes' appears with an emoji, which matches). The description is complete and specific.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 1cfb2e5 and c7c595e.

Files selected for processing: 3

  • .changeset/long-digit-alphanumeric-sort.md
  • packages/table-core/src/features/row-sorting/sortFns.ts
  • packages/table-core/tests/unit/fns/sortFns.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@oyobbeb
oyobbeb force-pushed the feat-alphanumeric-long-digit-runs branch 2 times, most recently from 1a621e9 to fe99ca8 Compare November 22, 2026 16:10
Digit runs longer than 15 significant digits fell back to parseInt,
which rounds once the value no longer fits in a double, so runs such as
1100000000000000001 and 1100000000000000002 compared as equal. Compare
the significant lengths instead, and runs of equal length as digit
strings.
@oyobbeb
oyobbeb force-pushed the feat-alphanumeric-long-digit-runs branch from fe99ca8 to c7c595e Compare November 22, 2026 16:28
@oyobbeb
oyobbeb marked this pull request as ready for review November 22, 2026 16:30

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant